package com.foxit.pdf2html5.common;

import java.net.URL;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;
import org.springframework.core.io.UrlResource;
import org.springframework.web.context.ContextLoaderListener;

import com.foxit.conver2bin.task.ConversionEntrance;
import com.foxit.pdf2html5.common.utils.GetBean;


/**
 * @author shaojie_zhuo
 * @version 1.0
 * Web Reader Startup listener class.
 */
public class ProgramStartupListener extends ContextLoaderListener implements ServletContextListener{
	
	private static final Logger log = Logger.getLogger(ProgramStartupListener.class);
	 @Override
	 public void contextInitialized(ServletContextEvent event) {
		
		 super.contextInitialized(event);
		 init();
	 }
	 
	 public void contextDestroyed(ServletContextEvent sce) {  
		 super.contextDestroyed(sce);
	  }  
	 
		public static void init(){
			try
			{
				URL appContextBeansXmlPath = ConversionEntrance.class.getResource("/ConversionContextBeans.xml");
				UrlResource  appContextBeansXmlResouce = new UrlResource (appContextBeansXmlPath);  
				GetBean.InitContext(appContextBeansXmlResouce);
				
				
			}
			catch(Exception ex)
			{
				log.error("Spring initialize failed."+ex);
				return;
			}

		}
}
